package com.dduggs.note.date;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;

/**
 * Created by CJS on 2017/4/5.
 */
public class LocalDateTest {

    public static void main(String[] args) {
        LocalDate today = LocalDate.now(); // -> 2017-04-01
        LocalDate crischristmas = LocalDate.of(2017, 4, 01); // -> 2017-04-01
        LocalDate endOfFeb = LocalDate.parse("2017-04-01");
//        LocalDate.parse("2017-02-29"); // 无效日期无法通过：DateTimeParseException: Invalid date...

        LocalDate firstDayOfThisMonth = today.with(TemporalAdjusters.firstDayOfMonth()); // 2014-12-01
        LocalDate secondDayOfThisMonth = today.withDayOfMonth(2); // 2014-12-02
        LocalDate lastDayOfThisMonth = today.with(TemporalAdjusters.lastDayOfMonth()); // 2014-12-31
// 取下一天：
        LocalDate firstDayOf2015 = lastDayOfThisMonth.plusDays(1); // 变成了2015-01-01
// 取2015年1月第一个周一，这个计算用Calendar要死掉很多脑细胞：
        LocalDate firstMondayOf2015 = LocalDate.parse("2017-01-01").with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY)); // 2015-01-05
        System.out.println(today);
        System.out.println(crischristmas);
        System.out.println(endOfFeb);
        System.out.println(firstDayOfThisMonth);
        System.out.println(secondDayOfThisMonth);
        System.out.println(lastDayOfThisMonth);
        System.out.println(firstDayOf2015);
        System.out.println(firstMondayOf2015);
    }
}
